package test4_11.demo05;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

public class Homework21_9 {
    //定义一个学生类 Student,有属性,Date brith,String name,int height,String degree,
    //定义两个对象,将此对象写到文件中,并在另外一个工程中,将些内容读出.
    public static void main(String[] args) throws Exception {

        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D://b.txt"));
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D://b.txt"));

        List<Student> students = Arrays.asList(
                new Student(new Date(104, 2, 3), "tom", 178, "本科"),
                new Student(new Date(104, 2, 8), "jerry", 165, "本科")
        );
        oos.writeObject(students);

        oos.flush();
        oos.close();

        List<Student> list = (List<Student>)ois.readObject();
        for (Student s : list) {
            System.out.println(s);
        }

        ois.close();

    }
}
